package cn.iocoder.yudao.module.member.service.praxisProjectSchedule;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.controller.admin.praxisProject.vo.PraxisProjectScheduleVO;
import cn.iocoder.yudao.module.member.dal.dataobject.praxisProjectSchedule.PraxisProjectScheduleDO;
import cn.iocoder.yudao.module.member.dal.mysql.praxisProjectSchedule.PraxisProjectScheduleMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目赛程安排 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class PraxisProjectScheduleServiceImpl implements PraxisProjectScheduleService {

    @Resource
    private PraxisProjectScheduleMapper praxisProjectScheduleMapper;

    @Override
    public void save(PraxisProjectScheduleDO d) {
        praxisProjectScheduleMapper.insert(d);
    }

    @Override
    public void batchSaveProjectSchedule(List<PraxisProjectScheduleDO> list) {
        praxisProjectScheduleMapper.insertBatch(list);
    }

    @Override
    public void deleteProjectScheduleByProjectId(Long projectId) {
        praxisProjectScheduleMapper.delete(new QueryWrapper<PraxisProjectScheduleDO>().eq("project_id",projectId));
    }

    @Override
    public List<PraxisProjectScheduleDO> getPraxisProjectScheduleList(PraxisProjectScheduleVO exportReqVO) {
        return praxisProjectScheduleMapper.selectList(exportReqVO);
    }

    @Override
    public List<PraxisProjectScheduleVO> getScheduleListByProjectId(Long projectId) {
        return praxisProjectScheduleMapper.getScheduleListByProjectId(projectId);
    }

    @Override
    @TenantIgnore
    public PraxisProjectScheduleVO getScheduleByProjectId(Long projectId, Integer scheduleType) {
        PraxisProjectScheduleDO scheduleDO = praxisProjectScheduleMapper.selectOne(new QueryWrapper<PraxisProjectScheduleDO>()
                .eq("project_id", projectId).eq("schedule_type", scheduleType).last(" limit 1"));
        PraxisProjectScheduleVO scheduleVO=null;
        if(null!=scheduleDO){
            scheduleVO=new PraxisProjectScheduleVO();
            BeanUtils.copyProperties(scheduleDO,scheduleVO);
        }
        return  scheduleVO;
    }
}
